package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

public interface OrdersMapper {
    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    OrderVO queryOrderDetailById(Long id);

    /**
     * 分页查询历史订单
     * @param dto
     * @return
     */
    Page<OrderVO> queryOrders(OrdersPageQueryDTO dto);


    /**
     * 订单搜索
     * @param dto
     */
    Page<OrderVO> conditionSearch(OrdersPageQueryDTO dto);

    /**
     * 各个订单统计
     *
     * @return
     */
    @MapKey("status")
    List<Map> statistics();

    /**
     * 查询超时的订单
     * @param status
     * @param time
     * @return
     */
    @Select("select * from orders where status=#{status} and order_time<#{time}")
    List<Orders> overduePayment(Integer status, LocalDateTime time);

    /**
     * 查询一点未送达的订单
     * @param status
     * @param time
     * @return
     */
    @Select("select * from orders where status=#{status} and estimated_delivery_time<#{time}")
    List<Orders> timeOrdersDaily(Integer status, LocalDateTime time);


}
